package com.qyl.honghengshop.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.qyl.honghengshop.dao.BaseDao;
import com.qyl.honghengshop.dao.PictureDao;
import com.qyl.honghengshop.dto.PictureCarousel;
import com.qyl.honghengshop.mapper.PictureMapper;
import com.qyl.honghengshop.utils.PageBean;

public class PictureDaoImpl extends BaseDao implements PictureDao {

	@Override
	public int getRecordCount(PictureCarousel picture) {
		
		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		int recordCount = pictureMapper.getRecordCount(picture);
		
		this.closeSqlSession();
		
		return recordCount;
	}

	@Override
	public void pictureList(PageBean pageBean, PictureCarousel picture) {

		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		List<PictureCarousel> list =  pictureMapper.pictureList(pageBean,picture);
		
		pageBean.setList(list);
		
		this.closeSqlSession();

		
	}

	@Override
	public int pictureAdd(PictureCarousel picture) {

		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		int count = pictureMapper.pictureAdd(picture);
		
		sqlSession.commit();
		
		this.closeSqlSession();

		return count;
	}

	@Override
	public int delPic(Integer id) {
		
		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		int count = pictureMapper.delPic(id);
		
		sqlSession.commit();
		
		this.closeSqlSession();

		return count;
	}

	@Override
	public PictureCarousel getPicById(Integer id) {
		
		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		PictureCarousel picture = pictureMapper.getPicById(id);
		
		this.closeSqlSession();
		
		return picture;
	}

	@Override
	public int pictureUpdate(PictureCarousel picture) {

		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		int count = pictureMapper.pictureUpdate(picture);
		
		sqlSession.commit();
		
		this.closeSqlSession();

		return count;
	}

	@Override
	public List<PictureCarousel> allPictureList() {

		SqlSession sqlSession = this.getSqlSession();
		
		PictureMapper pictureMapper = sqlSession.getMapper(PictureMapper.class);
		
		List<PictureCarousel> list =  pictureMapper.allPictureList();
	
		this.closeSqlSession();
		
		return list;
	}

}
